//
//  HomeOptionDataShared.m
//  BigTyre
//
//  Created by 田涛 on 2017/3/28.
//  Copyright © 2017年 Lemon. All rights reserved.
//

#import "HomeOptionDataShared.h"
#import "HomeOptionModel.h"

#import <AFNetworking.h>

static HomeOptionDataShared *dataShared = nil;
@implementation HomeOptionDataShared

 /** 单例*/
+ (instancetype)sharedData {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        dataShared = [[HomeOptionDataShared alloc] init];
    });
    return dataShared;
}

+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    if (!dataShared) {
        dataShared = [super allocWithZone:zone];
    }
    return dataShared;
}

- (id)copy {
    return self;
}

- (id)mutableCopy {
    return self;
}


- (void)getURL:(NSString *)url data:(dataBlock)data{
    NSLog(@"%@",url);
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager GET:url parameters:self progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSArray *product = [(NSDictionary *)responseObject objectForKey:@"product"];
        _dataArr = [NSMutableArray array];
        for (NSDictionary *dic in product) {
            HomeOptionModel *model = [[HomeOptionModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [_dataArr addObject:model];
        }
        if (data) {
            data(_dataArr);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}


@end
